package socket;

import com.alibaba.fastjson.JSON;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @program JavaBase
 * @description:
 * @author: zhanglu
 * @create: 2019-06-12 08:54:00
 */
public class Client01 {

    public static void main(String[] args) {
        try {
            Socket s = new Socket("127.0.0.1", 8989);
            OutputStream os = s.getOutputStream();
            DataOutputStream dos = new DataOutputStream(os);
            InputStream is = s.getInputStream();
            DataInputStream dis = new DataInputStream(is);

            while(true){
                Scanner sc = new Scanner(System.in);
                String str = sc.next();
                Map<String,Object> map = new HashMap<>();
                map.put("op", 1);
                map.put("exec", str);
                dos.writeUTF(JSON.toJSONString(map));
                String msg = dis.readUTF();
                System.out.println("收到服务端信息"+msg);
            }

        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
